package com.ubs.training.server.service;

import com.ubs.training.prod.server.service.LoggingService;
import com.ubs.training.server.dao.ContractDao;
import com.ubs.training.server.dao.model.Contract;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * Created with IntelliJ IDEA.
 * User: xubuntu
 * Date: 8/22/12
 * Time: 3:54 AM
 * To change this template use File | Settings | File Templates.
 */

@Service
public class ContractService {
    @Autowired
    @Qualifier("jdbcContractDao")
    ContractDao dao;

    @Autowired
    LoggingService svc;

    public LoggingService getSvc() {
        return svc;
    }

    public void setSvc(LoggingService svc) {
        this.svc = svc;
    }

    public ContractDao getDao() {
        return dao;
    }

    public void setDao(ContractDao dao) {
        this.dao = dao;
    }

    public List<Contract> getByClientId(int clientId) {
        return dao.getByClientId(clientId);
    }

    public Contract getById(int contractId) {
        return dao.getById(contractId);
    }

    public void save(Contract contract) {
        if (isNew(contract)){
            dao.add(contract);
        }
        else {
            dao.update(contract);
        }
    }

    public void delete(Contract contract) {
        dao.delete(contract);
    }


    public void delete(int contractId) {
        dao.delete(contractId);
    }

    public boolean isNew(Contract contract){
        if (contract.getIdContract()==0) {
            return true;
        }
        else {
            return false;
        }
    }
}